extends ColorRect
signal animation_comlpeted
signal animation_disapper

var live = true

var cai = 0

var h = false

@onready var click_sound: AudioStreamPlayer = $Click

func animated_grid() -> void:
	var tween = create_tween()
	tween.tween_property(material,"shader_parameter/animation_progress",1.0,1)
	tween.tween_callback(func():emit_signal("animation_comlpeted"))
	tween.tween_property(material,"shader_parameter/animation_progress",0.0,1)
	tween.tween_callback(func():emit_signal("animation_disapper"))

func _input(event):
	if event is InputEventMouseButton and event.pressed and event.button_index == MOUSE_BUTTON_LEFT:
		if click_sound:
			# 如果音效已经在播放，复制一个新的实例播放
			if click_sound.playing:
				var new_sound = click_sound.duplicate()
				add_child(new_sound)
				new_sound.play()
				# 播放完后自动删除
				new_sound.finished.connect(new_sound.queue_free)
			else:
				click_sound.play()

func _process(delta: float) -> void:
	h = Input.is_action_pressed("h_action")
